import { approvalAds, returnAds } from '@/services/ads';
import { Button, message, Modal } from 'antd';
import styles from '../index.less';

type Props = {
  handleCancel: () => void;
  current: any;
  getList: () => void;
};

const SealModal: React.FC<Props> = ({ handleCancel, current, getList }) => {
  const colorThem = localStorage.getItem('color') || '#1a7721';
  console.log(current);

  const approvaledAds = async () => {
    try {
      await approvalAds({
        ...current,
        ifApproval: '1',
      }).then(() => {
        handleCancel();
        getList();
        message.success('审批通过！');
      });
    } catch (error) {
      console.log(error);
    }
  };

  const returnedAds = async () => {
    try {
      await returnAds({
        id: current.id,
        ifApproval: '2',
      }).then(() => {
        handleCancel();
        getList();
        message.success('已打回审批！');
      });
    } catch (error) {
      console.log(error);
    }
  };

  return (
    <Modal
      visible={true}
      footer={null}
      onCancel={handleCancel}
      className={styles.modalStyle}
      width={500}
      centered={true}
    >
      <div className={styles.modalContent}>
        <div className={styles.bigText}>请选择您要进行的操作？</div>
      </div>
      <div className={styles.btns}>
        <Button
          onClick={approvaledAds}
          className={styles.btnSeal}
          style={{ background: `${colorThem}` }}
        >
          通过申请
        </Button>
        <Button onClick={returnedAds} className={styles.btnCancel}>
          退回申请
        </Button>
      </div>
    </Modal>
  );
};

export default SealModal;
